﻿@model FC.Data.ViewModels.Contests.ProblemList

@{
    ViewBag.Title = "Problems";
    Layout = "~/Views/Shared/_ManagerLayout.cshtml";
}

@section Buttons{
    <a class="btn btn-success" href="~/Manager/EditProblem/@ViewBag.Collection">添加题目</a>
    <button id="btnClear" class="btn btn-danger" onclick="Clear('@ViewBag.Collection')">清空试题集</button>
    <a class="btn btn-info" href="~/Manager/ImportFromWeb/@ViewBag.Collection">网站导入</a>
    <a class="btn btn-gray" href="~/Manager/Export/@ViewBag.Collection">全部导出</a>
}
<table class="table">
    <tr>
        <th>
            编号
        </th>
        <th>
            标题
        </th>
        <th>
            分类
        </th>
        <th></th>
    </tr>

@foreach (var item in Model.Problems) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.No)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Keyword)
        </td>
        <td>
            <a class="btn btn-info" href="~/Manager/EditProblem/@ViewBag.Collection/@item.No" style="height:24px;padding:2px 10px">编辑</a>
            <a class="btn btn-danger" href="#" onclick="Delete('@ViewBag.Collection', '@item.No')" style="height:24px;padding:2px 10px">删除</a>
        </td>
    </tr>
}

</table>
<ul class="pagination" style="margin-top:0">
    <li><a href="~/Manager/Problems/@ViewBag.Collection">首页</a></li>
    @for (int i = 1; i <= Model.PageCount; i++)
    {
        if (i == Model.Page)
        {
            <li><a href="#">@i</a></li>
        }
        else
        {
            <li><a href="~/Manager/Problems/@ViewBag.Collection?Page=@i">@i</a></li>
        }
    }
    <li><a href="~/Manager/Problems/@ViewBag.Collection?Page=@Model.PageCount">尾页</a></li>
</ul>
@section Script{
    <script>
        function Delete(collection, code) {
            if (confirm("确定要删除该题目吗？")) {
                $.ajax({
                    type: "post",
                    url: "/Manager/DeleteProblem/" + collection + "/" + code,
                    success: function (result) {
                        if (result.state == "ok") {
                            alert("删除成功");
                            window.location = "/Manager/Problems/" + collection;
                        }
                        else {
                            alert(result.message);
                        }
                    }
                });
            }
        }
        function Clear(collection) {
            if (confirm("确定要清空该题目集吗？")) {
                $.ajax({
                    type: "post",
                    url: "/Manager/ClearCollection/" + collection,
                    success: function (result) {
                        if (result.state == "ok") {
                            alert("删除成功");
                            window.location = "/Manager/Problems/" + collection;
                        }
                        else {
                            alert(result.message);
                        }
                    }
                });
            }
        }
    </script>
}